package com.example.demo.T1.V2;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * T1..
 *
 * @author Lizhong
 * @date 2020/8/18
 */
public class T1 {


    public static void main(String[] args) {

    }


    /**
     * 重写 ProA、ProB equals方法
     *
     * @param arrProA
     * @param arrProB
     * @return
     */

    public static MergedAB[] merge(ProA[] arrProA, ProB[] arrProB) {
        //尽量采用较低的时间复杂度和空间复杂度来实现

        Map proAMap = new HashMap<>();
        for (ProA proA : arrProA) {
            if(proA==null) continue;
            proAMap.put(proA, proA);
        }
        List<MergedAB> mergedABS = new ArrayList<>();
        for (ProB proB : arrProB) {
            if(proB==null) continue;

            ProA proA = (ProA) proAMap.get(proB);
            if (proA == null) continue;

            MergedAB e = new MergedAB();
            e.key1 = proA.key1;
            e.key2 = proA.key2;
            e.v1 = proA.v1;
            e.v2 = proB.v2;
            mergedABS.add(e);
            proAMap.remove(proB);

        }
        MergedAB[] mergedABS1 = new MergedAB[mergedABS.size()];
        mergedABS.toArray(mergedABS1);
        return mergedABS1;

    }


}


